const app = getApp();

function toast(title, type = 'none', duration = 1000) {
    wx.showToast({
        title: title,
        icon: type,
        duration: duration
    })
}

/*
content：提示内容
showCancel：是否显示取消按钮
handleCallback：是否要处理回调
callback：回调函数
*/
function dialog(content, showCancel = false, handleCallback = false, callback) {
    wx.showModal({
        title: '温馨提示',
        content: content,
        showCancel: showCancel,
        success(res) {
            if (res.confirm) {
                if (handleCallback) {
                    return callback();
                }
            } else if (res.cancel) {
                return false;
            }
        }
    })
}

function canvasRpx() {
    return app.globalData.screenWidth / 375;
}

module.exports = {
    toast: toast,
    dialog: dialog,
    canvasRpx: canvasRpx,
};